from rest_framework import serializers

from Admin.models import RemoteProblem
from Problems.serializers import ProblemTagSerializer


class RemoteProblemSerializer(serializers.ModelSerializer):
    tags = ProblemTagSerializer(many=True)
    remoteOJ = serializers.SerializerMethodField()
    remoteId = serializers.CharField(source='remote_id')
    remoteUrl = serializers.CharField(source='remote_url')

    class Meta:
        model = RemoteProblem
        fields = (
            'name',
            'remoteOJ',
            'remoteId',
            'remoteUrl',
            'rating',
            'tags',
            'solvedCount',
            'is_get_problem_success',
        )

    def get_remoteOJ(self, obj):
        return obj.remote_oj.name
